<script setup lang="ts">
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'

let charts = ref()
onMounted(() => {
  let myCharts = echarts.init(charts.value)
  myCharts.setOption({
    // tooltip: {
    //   trigger: 'item'
    // },
    legend: {
      top: '20%',
      left: 'right',
      orient: 'verticalAlign',
      textStyle: {
        color: '#fff',
        fontStyle: 32,
      },
    },
    series: [
      {
        name: '年龄比例',
        type: 'pie',
        radius: ['40%', '80%'],
        center: ['40%', '50%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
        },
        label: {
          show: true,
          position: 'inside',
          color: '#fff',
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 20,
            fontWeight: 'bold',
          },
        },
        labelLine: {
          show: false,
        },
        data: [
          { value: 16, name: '10岁以下 16%' },
          { value: 8, name: '10-18岁 8%' },
          { value: 12, name: '18-30岁 12%' },
          { value: 24, name: '30-40岁 24%' },
          { value: 20, name: '40-60岁 20%' },
          { value: 20, name: '60岁以上 20%' },
        ],
      },
    ],
  })
})
</script>

<template>
  <div class="sex">
    <div class="title">
      <p>年龄比例</p>
      <div class="img"></div>
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<style scoped lang="scss">
.sex {
  height: 340px;
  background: url('../images/dataScreen-main-lt.png') no-repeat;
  background-size: cover;
  color: white;
  position: relative;
  .title {
    font-size: 24px;
  }
  .img {
    width: 68px;
    height: 7px;
    background: url('../images/dataScreen-title.png') no-repeat;
    background-size: cover;
    margin-top: 8px;
  }
  .charts {
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 75%;
  }
}
</style>
